package cn.guice;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class TransactionInterceptor implements MethodInterceptor{
	
	private final static Log log = LogFactory.getLog(TransactionInterceptor.class);
	
	public Object invoke(MethodInvocation invocation) throws Throwable {
		
		Object obj=null;
		try {
			System.out.println("Transaction:autoCommit->false");
			log.info("Transaction:autoCommit->false");
			obj = invocation.proceed();
		} catch (Exception e) {
			log.info("Transaction:rollback");
			e.printStackTrace();
		}
		log.info("Transaction:Commit");
	    return obj;
	}

}
